package com.heima.feigns.fallback;

import com.heima.feigns.AdminFegin;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author lo
 * @date 2021/9/25
 */
@Component
@Slf4j
public class AdminFeginFallback implements FallbackFactory<AdminFegin> {
    @Override
    public AdminFegin create(Throwable throwable) {
        throwable.printStackTrace();
        return new AdminFegin() {
            @Override
            public ResponseResult sensitives() {
                log.error("查询敏感词远程调用失败,失败原因: {}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult findOne(Integer id) {
                log.error("参数为: {}",id);
                log.error("查询敏感词远程调用失败,失败原因: {}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }

            @Override
            public ResponseResult getChannelList() {
                log.error("查询频道列表远程调用失败getChannelList,失败原因: {}",throwable.getMessage());
                return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
            }
        };
    }
}
